package com.by.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;

/**
 * @version 1.0
 * @Author 彭彦彬
 * @Date 2025/4/3 15:41
 * @注释
 */
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 获取所有请求头的名称
        Enumeration<String> headerNames = request.getHeaderNames();

        // 遍历并打印每个请求头及其对应的值
        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            String headerValue = request.getHeader(headerName);
            System.out.println(headerName + ": " + headerValue);
        }

        // 打印 handler 对象（可选）
        System.out.println("Handler: " + handler);

        return true; // 继续执行后续流程
    }
}
